package hcn.sync.core.row;

import java.io.Serializable;
import java.util.Date;

/**
 * Created by chase on 2016/11/30.
 */
public class ResultMeta implements ResultMetaInterface, Serializable {
    private Object statusCountersLock = new Object();
    private String methodName;
    private String serviceId;
    private String msg = "success";//执行日志
    private String eventId;//记录ID
    private String orgId;
    private String logId;//日志ID
    private int code = 200;//代码
    private long linesWritten = 0;//正确数量
    private long linesRejected = 0;//拒绝数量
    private long linesRead = 0;//读取数量
    private long linesUpdated = 0;//修改数量
    private long errors = 0;//错误数量
    private Date endTime;
    private String docContent;//文本数据
    private String entityName;
    private String clazz;
    private String action;

    public ResultMeta() {
        synchronized (statusCountersLock) {
            linesUpdated = 0L;
            linesWritten = 0L;
            linesRejected = 0L;
            code = 200;
            docContent = null;
            msg = "success";
        }
    }

    public String getServiceId() {
        return serviceId;
    }

    public void setServiceId(String serviceId) {
        this.serviceId = serviceId;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public String getEventId() {
        return eventId;
    }

    public void setEventId(String eventId) {
        this.eventId = eventId;
    }

    public String getLogId() {
        return logId;
    }

    public void setLogId(String logId) {
        this.logId = logId;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }


    public void setLinesWritten(long linesWritten) {
        this.linesWritten = linesWritten;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getOrgId() {
        return orgId;
    }

    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }

    public String getDocContent() {
        return docContent;
    }

    public void setDocContent(String docContent) {
        this.docContent = docContent;
    }

    public void setLinesRead(long linesRead) {
        this.linesRead = linesRead;
    }

    public long getErrors() {
        return errors;
    }

    public void setErrors(long errors) {
        this.errors = errors;
    }

    public long getLinesRead() {
        synchronized (statusCountersLock) {
            return linesRead;
        }
    }

    public long incrementLinesRead() {
        synchronized (statusCountersLock) {
            return ++linesRead;
        }
    }

    public long getLinesUpdated() {
        synchronized (statusCountersLock) {
            return linesUpdated;
        }
    }

    public long incrementLinesUpdated() {
        synchronized (statusCountersLock) {
            return ++linesUpdated;
        }
    }

    public long decrementLinesUpdated() {
        synchronized (statusCountersLock) {
            return --linesUpdated;
        }
    }

    public void setLinesUpdated(long newLinesUpdatedValue) {
        synchronized (statusCountersLock) {
            linesUpdated = newLinesUpdatedValue;
        }
    }

    public long getLinesRejected() {
        synchronized (statusCountersLock) {
            return linesRejected;
        }
    }

    public long incrementLinesRejected() {
        synchronized (statusCountersLock) {
            return ++linesRejected;
        }
    }

    public void setLinesRejected(long newLinesRejectedValue) {
        synchronized (statusCountersLock) {
            linesRejected = newLinesRejectedValue;
        }
    }

    public long getLinesWritten() {
        synchronized (statusCountersLock) {
            return linesWritten;
        }
    }

    public long incrementLinesWritten() {
        synchronized (statusCountersLock) {
            return ++linesWritten;
        }
    }

    public long decrementLinesWritten() {
        synchronized (statusCountersLock) {
            return --linesWritten;
        }
    }

    public long getLinesErrors() {
        synchronized (statusCountersLock) {
            return errors;
        }
    }

    public long incrementLinesErrors() {
        synchronized (statusCountersLock) {
            return ++errors;
        }
    }

    public long decrementLinesErrors() {
        synchronized (statusCountersLock) {
            return --errors;
        }
    }

    public String addEntityName(String entityName) {
        if (entityName != null && !entityName.isEmpty()) {
            setEntityName(getEntityName() + "," + entityName);
        }
        return getEntityName();
    }

    public String getEntityName() {
        return entityName;
    }

    public void setEntityName(String entityName) {
        this.entityName = entityName;
    }

    public String getClazz() {
        return clazz;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }
}
